const mongoose = require("mongoose")
const { Schema, model } = mongoose

const DramasSchema = new Schema({
    id_drama: {
        type: Number,
        unique: true,
        required: [true, "需要剧本ID"],

    },
    name: {
        type: String,
        unique: true,
        minlength: 0,
        maxlength: 15,
        required: [true, "请输入剧本名"],
        trim: true,
    },
    author: {
        type: String,
        default: "未知",
        minlength: 0,
        maxlength: 20,
        trim: true,
    },
    cover: {
        type: String,
        default: "无",
        trim: true,
    },
    tags: {
        type: [String],
        default: ["悬疑", "推理"]
    },

    price: {
        type: Number,
        default: 128
    }
    ,
    time: {
        type: Number,
        default: 300
    },
    num_played: {
        type: Number,
        default: 0
    },
    sum_score: {
        type: Number,
        default: 0.1,
        min: 0,
        max: 10
    },
    num_score: {
        type: Number,
        default: 0.0
    },
    num_comment:{
        type: Number,
        default: 0
    },
    description_drama: {
        type: String,
        required: [true, "请输入剧本描述"],
        minlength: 0,
        maxlength: 300,
        trim: true,
    },
    num_role: {
        type: Number,
        default: 0,
        min: 0,
        max: 50,
    },
    role: {
        type: {
            male: {
                type: String
            },
            female: {
                type: String
            }
        },
        default: { male: 0, female: 0 }
    },
    description_role: {
        type: String,
        default: "角色描述",
        minlength: 0,
        maxlength: 300,
        trim: true,
    },
    image_role: {
        type: String,
        default: "无",
        trim: true,
    },
    video_drama: {
        type: String,
        default: "无",
        trim: true,
    },
    image_drama: {
        type: String,
        default: "无",
        trim: true,
    },
    id_upload: {
        type: Number,
        default: 100001
    },
    id_update: {
        type: Number,
        default: 100001
    },
}, { timestamps: true, versionKey: false })

module.exports = model("Dramas", DramasSchema, "Dramas")